package javabase.schoolwork.day6_19;

import java.io.*;
import java.net.Socket;

/**
 * @author fance
 * @date 2018/6/19 23:06
 */
public class TCPClient {
    public static void main(String[] args) throws IOException {
        Socket client=null;
        client=new Socket("localhost", 8888);
        BufferedReader buf=null;
        buf=new BufferedReader(new InputStreamReader(client.getInputStream()));

        /*InputStream inputStream =
                client.getInputStream();
        receivePicture(inputStream);
        inputStream.close();*/

        OutputStream outputStream = client.getOutputStream();
        sendTxt(outputStream);
        outputStream.close();

        client.close();
        buf.close();
    }

    public static void receivePicture(InputStream in) throws IOException {

        FileOutputStream fileOutputStream =
                new FileOutputStream("src/javabase/schoolwork/day6_19/receive.jpg");

        byte[] buffer = new byte[1024];
        while (in.read(buffer) != -1) {
            fileOutputStream.write(buffer);
        }
    }

    public static void sendTxt(OutputStream out) throws IOException {
        FileInputStream fis=new FileInputStream("src/javabase/schoolwork/day6_19/receive.txt");
        byte[] b=new byte[1024];

        while(fis.read(b)!=-1) {

            out.write(b);
        }
    }



    }
